package com.yjy.controller;
// Tomcat 10+ 写法

import cn.hutool.core.util.StrUtil;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.github.pagehelper.PageInfo;
import com.yjy.common.Result;
import com.yjy.entity.Notice;
import com.yjy.service.NoticeService;
import jakarta.annotation.Resource;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;

@RestController
@RequestMapping("/notice")
public class NoticeController {

    @Resource
    NoticeService noticeService;

    @GetMapping("/selectAll")
    public Result selectAll(){
        List<Notice> notices = noticeService.selectAll(null);
        return Result.success(notices);
    }

    @PostMapping("/add")
    public Result add(@RequestBody Notice notice) {//@RequestBody 接受前端传来的json参数 get是接受不到json的 post delete put可以接受
        noticeService.add(notice);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody Notice notice) {//@RequestBody 接受前端传来的json参数 get是接受不到json的 post delete put可以接受
        noticeService.update(notice);
        return Result.success();
    }

    @DeleteMapping ("/delete/{id}")
    public Result delete(@PathVariable Integer id) {
        noticeService.deleteById(id);
        return Result.success();
    }


    /**
     * 分页查询
     * pageNum: 当前的页码
     * pageSize: 每页的个数
     */
    @GetMapping("/selectPage")
    public Result selectPage(@RequestParam(defaultValue = "1")Integer pageNum,
                             @RequestParam(defaultValue = "10")Integer pageSize,
                             Notice notice)
    {
                             //@RequestParam(required = false)String name){//也可以Notice notice
        PageInfo<Notice> noticePageInfo = noticeService.selectPage(pageNum, pageSize,notice);
        return Result.success(noticePageInfo); //返回的是分页的对象
    }



}
